<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="编号" hidden = true >
        <el-input v-model="form.id" style=" width: 300px"/>
      </el-form-item>
      <el-form-item label="省">
        <el-input v-model="form.province" style=" width: 300px"/>
      </el-form-item>
      <el-form-item label="市">
        <el-input v-model="form.city" style=" width: 300px"/>
      </el-form-item>
      <el-form-item label="区/县">
        <el-input v-model="form.area" style=" width: 300px"/>
      </el-form-item>
      <el-form-item label="详细地址">
        <el-input v-model="form.addressdetail" style=" width: 600px"/>
      </el-form-item>
      <el-form-item label="联系人">
        <el-input v-model="form.contactname" style=" width: 300px"/>
      </el-form-item>
      <el-form-item label="手机号码">
        <el-input v-model="form.phone" style=" width: 300px"/>
      </el-form-item>
      <el-form-item label="用户">
        <el-input v-model="form.userid" style=" width: 300px"/>
      </el-form-item>
       <el-form-item label="是否默认">
        <el-switch v-model="form.isdefault" />
      </el-form-item> 
      <el-form-item>
        <el-button type="primary" @click="onSubmit">确认</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

import { addOrUpdateAddress, addressById } from "@/api/address/address";

export default {
  data() {
    return {
      form: {
        id: '',
        province: '',
        city: '',
        area: '',
        addressdetail: '',
        contactname: '',
        phone: '',
        userid: '',
        isdefault: this.isdefault = false?'20':'10',
        isRemoved: '0'
      }
    }
  },
  created() {
    var row = this.$route.query
    if (row.id) {
      console.log('传值===', this.$route.query)
      this.form = this.$route.query
    }
  },
  methods: {
    onSubmit() {
      // this.$message('submit!')
      console.log('地址编辑信息==[' +JSON.stringify(this.form)+ ']')
      addOrUpdateAddress(this.form).then(res => {
        console.log("地址编辑返回信息==" + JSON.stringify(res))
        if (res.code === 200) {
          console.log("code === 200，地址编辑成功");
          this.$router.push(this.redirect || "/address" )
        }
      })
    },
    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      })
    }
  }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>

